var express = require('express');
var router = express.Router();
var { Types: { ObjectId } } = require('mongoose')
var { taskdataModel } = require('../module/user');
const bcryptjs = require("bcryptjs");

// 获取页面
router.get('/tasklist', async (req, res) => {
    // let page = req.query.page
    // let pagesize = req.query.pagesize
    let userlist = await taskdataModel.find({})
    let total = userlist.length
    console.log(1);
    // userlist = userlist.slice((page - 1) * pagesize, pagesize * page)
    res.send({ userlist, total })

});

// 添加数据
router.post('/tasklistdata', async (req, res) => {
    let query = req.body
    console.log(query);
    await taskdataModel.create({
        taskname: query.taskname,
        faname: query.faname,
        tasklevel: query.tasklevel,
        taskstart: query.taskstart,
        person: query.person,
        xieperson: query.xieperson,
        zhiperson: query.zhiperson,
        topdata: query.topdata,
        enddata: query.enddata,
        taskexplain: query.taskexplain,
    })
    res.send({ mag: "添加成功", code: 200 })
});
// 删除数据
router.delete("/deletetask/:id", async (req, res) => {
    let id = req.params.id
    await taskdataModel.deleteOne({ _id: id })
    console.log(id);
    res.send({
      code: 200,
      msg: "删除用户成功"
    })
  })

// 获取单个任务信息
router.get("/gettaskdan/:id", async (req, res) => {
    let id = req.params.id
    console.log(id);
    let tasklist = await taskdataModel.find({_id:id})
    console.log(tasklist);
    res.send({
      code: 200,
      data:tasklist,
    })
  })

module.exports = router